package com.cjb.cloudsystem.controller;

import com.cjb.cloudfabric.entity.DeviceStatus;
import com.cjb.cloudfabric.service.OperateFabricService;
import com.cjb.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @Author chenjinbin
 * @Package IntelliJ IDEA
 * @Class DeviceController
 * @Date 2024-03-02 下午2:29
 */
@RestController
@RequestMapping(value = "device/data")
@Tag(name = "数据上链码", description = "数据上链码 API")
@AllArgsConstructor
public class DeviceDataController {
    /**
     * 日志
     */
    private final static Logger log = LoggerFactory.getLogger(DeviceDataController.class);

    /**
     * 注入资产API
     */
    private final OperateFabricService operateFabricService;
    /**
     *
     * 新增设备数据
     * @Author chenjinbin
     * @Value
     * @Title
     */
    @PutMapping("/add")
    @Operation(summary = "新增设备数据")
    public Result<String> addAsset(@RequestBody DeviceStatus deviceStatus) throws Exception {
        log.info("新增设备数据");
        return Result.success(operateFabricService.SubmitDeviceData(deviceStatus));
    }
    /**
     *
     * 查看全部设备数据列表
     * @Author chenjinbin
     * @Value
     * @Title
     */
    @GetMapping("/getAllDeviceData")
    @Operation(summary = "查询全部资产")
    public Result<String> getAllDeviceData() throws Exception {
        log.info("获得请求");
        return Result.success(operateFabricService.QueryAllDeviceData());
    }
    /**
     *
     * 数据上链 模块
     * @Author chenjinbin
     * @Value
     * @Title
     */
    @GetMapping("/encryption")
    @Operation(summary = "查询全部资产")
    public Result<String> encryption() throws Exception {
        //非对称加密
        //1.获取密文 2.解密数据 3.数据上链
        return null;
    }
    /**
     * 读写分离 哨兵检查模块 检查成功生成验证证书 证书标明时间角色等信息
     *
     * @Author chenjinbin
     * @Value
     * @Title
     */
    public Result<String> dataInspect() {
        //查询区块数据
        //查询数据库数据
        //数据校验
        return null;
    }
}
